using UnityEngine;
using System.Collections;

public class Console : MonoBehaviour {
	
	public string command = "";
	// Use this for initialization
	void Update()
	{
		if(!command.Equals(""))
		{
			if(command.Contains(" move "))
			{
				string ObjectName = command.Substring(0,command.IndexOf(' '));
				int lastIndex = command.LastIndexOf(' ') + 1;
				string TargetName = command.Substring(lastIndex,command.Length - lastIndex);
				
				instantMove(ObjectName,TargetName);
			}else if(command.Contains("call "))
			{
				gameObject.SendMessage(command.Substring(5));
			}
		}
		command = "";
	}
	public static void testYield()
	{
		for(int i = 0;i< 50;i++)
		{
			new GameObject().transform.position =  new Vector3(0,i,0);
		}
	}
	public static void instantMove(string objectName,string targetName)
	{
		GameObject obj = GameObject.Find(objectName);
		if(obj == null)
		{
			print("has no such game object: " + objectName);
			return;
		}
		Transform objTrans = obj.transform;
		
		GameObject tar = GameObject.Find(targetName);
		
		if(tar == null)
		{
			print("has no such game object: " + targetName);
			return;
		}
		objTrans.position = tar.transform.position;
		
		print("GameObject: " + objectName + " has been moved to " + targetName);
		
	}
	void Start () {
		
		GameObject skillPool = GameObject.Find("SkillPool");
		GameObject weaponPool = GameObject.Find("WeaponPool");
		GameObject interactionGroup = GameObject.Find("InteractionGroup");
		
		
		if(interactionGroup == null)
		{
			print("No InteractionGroup, make sure all defender and attacker in this game Object.");
			return;
		}
		
		GameObject charactor = GameObject.Find("Charactor");
		
		if(charactor == null)
		{
			print("No Charactor in InteractionGroup");
			return;
		}
		
		if(skillPool == null)
		{
			print("No Skill Pool!!!");
			return;
		}
		
		if(weaponPool == null)
		{
			print("No Weapon Pool!!!");
			return;
		}
		
		if(skillPool.transform.childCount == 0)
		{
			print("Skill pool has no skill!!!");
			return;
		}
		
		if(weaponPool.transform.childCount == 0)
		{
			print("weapon pool has no weapon!!!");
			return;
		}
		
		GameObject pathNodeContainer = GameObject.Find("PathNodeContainer");
		if(pathNodeContainer == null){
			print("no PathNodeContainer");
			return;
		}
		print("Map State All OK!!!");
		
		
	}
	
	}
